/*
 * CanaryView.java
 */

package canary;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.prefs.Preferences;
import javax.swing.Timer;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.netbeans.saas.RestResponse;
import twitter.whatareyoudoingservice.twitterresponse.DirectMessageType;
import twitter.whatareyoudoingservice.twitterresponse.StatusType;

/**
 * The application's main frame.
 */
public class CanaryView extends FrameView {
    private final Preferences pref;
    private static final String UPDATINGMSG = "<html><body>(updating...)</body></html>";
    private static final String CONNECTMSG = "<html><body>(unable to connect to Twitter)</body></html>";
    private static final String NOHISTORYMSG = "<html><body>(there is no history available to show)</body></html>";
    private static final String NOTFETCHEDMSG = "<html><body>(history not yet fetched)</body></html>";
    private static final int MAXLIST = 10; // initialize status list
    private static final int MAXARCHIVE = 200; // initialize archive list
    private static final int MAXPAGES = 12; // some sane limit of archive pages to fetch
    private TwitterUtils twitter;
    private List<StatusType> recentList;
    private List<StatusType> repliesList;
    private List<DirectMessageType> msgsList;
    private final int queryInterval;
    private final Timer queryTimer;

    private final Timer messageTimer;

    private JDialog aboutBox;
    private LoginDialog loginDialog;
    private final JFrame mainFrame;
    private final boolean verbose;

    public CanaryView(SingleFrameApplication app) {
        super(app);

        CanaryApp myApp = (CanaryApp) app;
        verbose = myApp.beVerbose();
        twitter = new TwitterUtils();
        pref = Preferences.userNodeForPackage(CanaryView.class);
        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);

        updateField.getDocument().addDocumentListener(new FieldListener());
        
        queryInterval = pref.getInt("queryInterval", 300000);
        queryTimer = new Timer(queryInterval, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (verbose) System.out.println("CanaryView: querying server from timer");
                refresh();
            }
        });
        queryTimer.setRepeats(true);

        if (verbose) System.out.println("CanaryView: init");
        mainFrame = app.getMainFrame();
        if (!initialLogin()) {
//            app.exit();
        }
        initHTMLPane(recentPane);
        initHTMLPane(directMsgsPane);
        initHTMLPane(repliesPane);
        initHTMLPane(archivePane);
        archivePane.setText(NOTFETCHEDMSG);
        recentList = new ArrayList<StatusType>(MAXLIST);
        repliesList = new ArrayList<StatusType>(MAXLIST);
        msgsList = new ArrayList<DirectMessageType>(MAXLIST);

        refresh();
        queryTimer.start();
    }

/***** STATUS UPDATES *****/
    
    private void showFriendsStatus() {
        List<StatusType> statusList;
        StringBuffer sBuf;
        String text;
        String startID;
        
        recentPane.setText(UPDATINGMSG);
        sBuf = new StringBuffer();
        startID = (recentList.isEmpty() ? null : recentList.get(0).getId());
        statusList = twitter.getFriendsStatus(startID);
        if (statusList == null) {
            if (startID == null) {
                // first time
                recentPane.setText(CONNECTMSG);
            }
            return;
        }

        statusList.addAll(recentList);
        recentList = statusList;
        sBuf.append("<html><body>");
        for (StatusType type : statusList) {
            sBuf.append("<p><strong>");
            sBuf.append(type.getUser().getScreenName());
            sBuf.append(": ");
            sBuf.append("</strong>");
            text = TwitterUtils.tweetToHTML(type.getText());
            sBuf.append(text);
            sBuf.append("</p>");
        }
        sBuf.append("</body></html>");
        recentPane.setText(sBuf.toString());
        recentPane.setCaretPosition(0);
    }
    
    private void showUserStatus() {
        List<StatusType> archiveList;
        List<StatusType> statusList;
        StringBuffer sBuf;
        String text;
        
        archivePane.setText(UPDATINGMSG);
        sBuf = new StringBuffer();
        archiveList = new ArrayList<StatusType>(MAXARCHIVE);
        for (int page = 1; page <= MAXPAGES ; page++) {
            statusList = twitter.getArchive(Integer.toString(page));
            if ((statusList == null) || (statusList.isEmpty())) {
                break;
            }
            if (verbose) System.out.println("CanaryView: archive page count = " + statusList.size());
            archiveList.addAll(statusList);
        }
        
        if (verbose) System.out.println("CanaryView: archive total count = " + archiveList.size());
        
        if (archiveList.isEmpty()) {
            archivePane.setText(NOHISTORYMSG);
            return;
        }
        
        sBuf.append("<html><body>");
        for (StatusType type : archiveList) {
            sBuf.append("<p>");
            text = TwitterUtils.tweetToHTML(type.getText());
            sBuf.append(text);
            sBuf.append("</p>");
        }
        sBuf.append("</body></html>");
        archivePane.setText(sBuf.toString());
        archivePane.setCaretPosition(0);
    }
    
    private void showReplies() {
        List<StatusType> statusList;
        StringBuffer sBuf;
        String text;
        String startID;
        
        repliesPane.setText(UPDATINGMSG);
        sBuf = new StringBuffer();
        startID = (repliesList.isEmpty() ? null : repliesList.get(0).getId());
        statusList = twitter.getReplies(startID);
        if (statusList == null) {
            if (startID == null) {
                // first time
                repliesPane.setText(CONNECTMSG);
            }
            return;
        } 
        statusList.addAll(repliesList);
        repliesList = statusList;
        sBuf.append("<html><body>");
        for (StatusType type : statusList) {
            sBuf.append("<p><strong>");
            sBuf.append(type.getUser().getScreenName());
            sBuf.append(": ");
            sBuf.append("</strong>");
            text = TwitterUtils.tweetToHTML(type.getText());
            sBuf.append(text);
            sBuf.append("</p>");
        }
        sBuf.append("</body></html>");
        repliesPane.setText(sBuf.toString());
        repliesPane.setCaretPosition(0);
    }
    
    private void showDirectMessages() {
        List<DirectMessageType> msgList;
        StringBuffer sBuf;
        String text;
        String startID;

        directMsgsPane.setText(UPDATINGMSG);
        sBuf = new StringBuffer();
        startID = (msgsList.isEmpty() ? null : msgsList.get(0).getId());
        msgList = twitter.getDirectMsgs(startID);
        if (msgList == null) {
            if (startID == null) {
                // first time
                directMsgsPane.setText(CONNECTMSG);
            }
            return;
        }
        
        msgList.addAll(msgsList);
        msgsList = msgList;
        sBuf.append("<html><body>");
        for (DirectMessageType type : msgList) {
            sBuf.append("<p><strong>");
            sBuf.append(type.getSenderScreenName());
            sBuf.append(": ");
            sBuf.append("</strong>");
            text = TwitterUtils.tweetToHTML(type.getText());
            sBuf.append(text);
            sBuf.append("</p>");
        }
        sBuf.append("</body></html>");
        directMsgsPane.setText(sBuf.toString());
        directMsgsPane.setCaretPosition(0);
    }
    
/***** HELPER FUNCTIONS *****/
    
    private void initHTMLPane(JEditorPane pane) {
        pane.setContentType("text/html;charset=UTF-8");
        pane.getEditorKit().createDefaultDocument();
        pane.setText("<html><body>(not updated)</body></html>");
    }
    
    private boolean initialLogin() {
        RestResponse result;
        String resultString;
        boolean workedOK = false;
        
        showStatus("Attempting login...");
        result = twitter.verifyLogin();
        if (result == null) {
            JOptionPane.showMessageDialog(mainFrame, "Unable to verify Twitter login at this time.", "Log In Error", JOptionPane.ERROR_MESSAGE);
        } else {
            if (verbose) System.out.println("LoginDialog: result = " + result.getDataAsString());
            resultString = TwitterUtils.requestResponse(result);
            if (resultString != null) {
                JOptionPane.showMessageDialog(mainFrame, resultString, "Log In Error", JOptionPane.ERROR_MESSAGE);
            } else { 
                workedOK = true;
            }
        }
        return workedOK;
    }

    private void refresh() {
        if (verbose) System.out.println("CanaryView: refresh");
        showStatus("Updating statuses...");
        showFriendsStatus();
        showReplies();
        showDirectMessages();
        showStatus("Update complete.");
    }
    
    private void showStatus(String msg) {
        if (msg != null) {
            statusMessageLabel.setText(msg);
            statusMessageLabel.repaint();
            messageTimer.restart();
        }
    }
    
/***** ACTIONS *****/
    
    @Action
    public void logIn() {
        if (loginDialog == null) {
            loginDialog = new LoginDialog(mainFrame);
            loginDialog.setLocationRelativeTo(mainFrame);
        }
        CanaryApp.getApplication().show(loginDialog);
        if (loginDialog.successfulLogin()) {
            refresh();
        }
    }
    
    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            aboutBox = new CanaryAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        CanaryApp.getApplication().show(aboutBox);
    }

    @Action
    public void checkNow() {
        refresh();
        queryTimer.restart();
    }

    @Action
    public void clearAction() {
        updateField.setText(null);        
    }
    
    @Action
    public void sendUpdate() {
        RestResponse result;
        String resultString;

        result = twitter.updateStatus(updateField.getText());
        if (result == null) {
            JOptionPane.showMessageDialog(mainFrame, "Unable to update your Twitter status at this time.","Status Update Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        resultString = TwitterUtils.requestResponse(result);
        if (resultString != null) {
            JOptionPane.showMessageDialog(mainFrame, resultString, "Status Update Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        updateField.setText(null);   
    }

    @Action
    public void fetchArchive() {
        showStatus("Fetching archive...");
        showUserStatus();
        showStatus("Archive fetched.");
    }

    @Action
    public void copyToClipboard() {
        archivePane.selectAll();
        archivePane.copy();
        JOptionPane.showMessageDialog(mainFrame, "Archive copied to clipboard.", "Copy to Clipboard", JOptionPane.INFORMATION_MESSAGE);
    }

/***** EMBEDDED CLASSES *****/

    private final class FieldListener implements DocumentListener {

        public void insertUpdate(DocumentEvent dEvt) {
            updateCharCount();
        }

        public void removeUpdate(DocumentEvent arg0) {
            updateCharCount();
        }

        public void changedUpdate(DocumentEvent arg0) {
            updateCharCount();
        }
        
        private void updateCharCount() {
            int charCount;
            
            charCount = updateField.getText().length();
            charCountLabel.setText(charCount + " of 140");
            sendButton.setEnabled((charCount <= 140) && (charCount > 0));
            clearButton.setEnabled(charCount > 0);
        }
    }

    /*
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        recentPane = new javax.swing.JEditorPane();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        updateField = new javax.swing.JTextArea();
        charCountLabel = new javax.swing.JLabel();
        sendButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        repliesPane = new javax.swing.JEditorPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        directMsgsPane = new javax.swing.JEditorPane();
        jPanel5 = new javax.swing.JPanel();
        fetchButton = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        archivePane = new javax.swing.JEditorPane();
        copyButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        loginMenuItem = new javax.swing.JMenuItem();
        checkMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(canary.CanaryApp.class).getContext().getResourceMap(CanaryView.class);
        jTabbedPane1.setBackground(resourceMap.getColor("jTabbedPane1.background")); // NOI18N
        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        recentPane.setBackground(resourceMap.getColor("recentPane.background")); // NOI18N
        recentPane.setName("recentPane"); // NOI18N
        jScrollPane1.setViewportView(recentPane);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        updateField.setColumns(20);
        updateField.setLineWrap(true);
        updateField.setRows(5);
        updateField.setWrapStyleWord(true);
        updateField.setName("updateField"); // NOI18N
        jScrollPane4.setViewportView(updateField);

        charCountLabel.setFont(resourceMap.getFont("charCountLabel.font")); // NOI18N
        charCountLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        charCountLabel.setText(resourceMap.getString("charCountLabel.text")); // NOI18N
        charCountLabel.setName("charCountLabel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(canary.CanaryApp.class).getContext().getActionMap(CanaryView.class, this);
        sendButton.setAction(actionMap.get("sendUpdate")); // NOI18N
        sendButton.setText(resourceMap.getString("sendButton.text")); // NOI18N
        sendButton.setName("sendButton"); // NOI18N

        clearButton.setAction(actionMap.get("clearAction")); // NOI18N
        clearButton.setText(resourceMap.getString("clearButton.text")); // NOI18N
        clearButton.setActionCommand(resourceMap.getString("clearButton.actionCommand")); // NOI18N
        clearButton.setName("clearButton"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(charCountLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, Short.MAX_VALUE)
                        .addComponent(clearButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sendButton)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sendButton)
                        .addComponent(clearButton))
                    .addComponent(charCountLabel))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        repliesPane.setBackground(resourceMap.getColor("repliesPane.background")); // NOI18N
        repliesPane.setName("repliesPane"); // NOI18N
        jScrollPane2.setViewportView(repliesPane);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        directMsgsPane.setBackground(resourceMap.getColor("directMsgsPane.background")); // NOI18N
        directMsgsPane.setName("directMsgsPane"); // NOI18N
        jScrollPane3.setViewportView(directMsgsPane);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        fetchButton.setAction(actionMap.get("fetchArchive")); // NOI18N
        fetchButton.setText(resourceMap.getString("fetchButton.text")); // NOI18N
        fetchButton.setName("fetchButton"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        archivePane.setBackground(resourceMap.getColor("archivePane.background")); // NOI18N
        archivePane.setName("archivePane"); // NOI18N
        jScrollPane5.setViewportView(archivePane);

        copyButton.setAction(actionMap.get("copyToClipboard")); // NOI18N
        copyButton.setText(resourceMap.getString("copyButton.text")); // NOI18N
        copyButton.setName("copyButton"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(copyButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fetchButton)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(fetchButton)
                    .addComponent(copyButton))
                .addContainerGap())
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE)
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        loginMenuItem.setAction(actionMap.get("logIn")); // NOI18N
        loginMenuItem.setText(resourceMap.getString("loginMenuItem.text")); // NOI18N
        loginMenuItem.setName("loginMenuItem"); // NOI18N
        fileMenu.add(loginMenuItem);

        checkMenuItem.setAction(actionMap.get("checkNow")); // NOI18N
        checkMenuItem.setText(resourceMap.getString("checkMenuItem.text")); // NOI18N
        checkMenuItem.setName("checkMenuItem"); // NOI18N
        fileMenu.add(checkMenuItem);

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addContainerGap(388, Short.MAX_VALUE))
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(statusMessageLabel)
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JEditorPane archivePane;
    private javax.swing.JLabel charCountLabel;
    private javax.swing.JMenuItem checkMenuItem;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton copyButton;
    private javax.swing.JEditorPane directMsgsPane;
    private javax.swing.JButton fetchButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JMenuItem loginMenuItem;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JEditorPane recentPane;
    private javax.swing.JEditorPane repliesPane;
    private javax.swing.JButton sendButton;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextArea updateField;
    // End of variables declaration//GEN-END:variables
}
